<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.title" placeholder="标题/作者/来源" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        搜索
      </el-button>
    </div>
    <el-row>
  <el-col :span="8" v-for="(row, index) in list" :key="row" :offset="index%4 == 0 ? 2 : 0">
    <el-card :body-style="{ padding: '0px' }">
      <img :src="row.cover" class="image">
      <div style="padding: 14px;">
        <span>{{ row.title }}</span>
        <div class="bottom clearfix">
          <el-button type="text" class="button">订购</el-button>
          <el-button type="text" class="button">查看详情</el-button>
        </div>
      </div>
    </el-card>
  </el-col>
</el-row>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.start" :limit.sync="listQuery.perpage" @pagination="getList" />

  </div>
</template>

<script>
import { getApplicationByUsable } from '@/api/program/application'
import waves from '@/directive/waves' // waves directive
import { parseTime } from '@/utils'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination

export default {
  name: 'productAdmin',
  components: { Pagination },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      selectedIDs:[],
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        start: 1,
        perpage: 40,
        title: undefined,
        sort: '+id'
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      getApplicationByUsable(this.listQuery).then(response => {
        this.list = response.data.list
        this.total = response.data.total

        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      })
    },
    handleSelectionChange(item) {
      this.selectedIDs = [];
      item.forEach((row)=>{
        this.selectedIDs.push(row['ID'])
      });
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    handleRecall(row, index) {
      this.getList()
    }
  }
}
</script>
